#ifndef __LAMBERTIAN__
#define __LAMBERTIAN__

#include "RGBColor.h"
#include "BRDF.h"
#include "Common.h"
#include "Texture.h"
#include "Triangle.h"

namespace Engine
{
	class Lambertian : public Engine::BRDF
	{
	public:
			Lambertian() :m_kd(0), m_cd(0)
			{}

			Lambertian(float& p_kd, RGBColor& p_cd) : m_kd(p_kd), m_cd(p_cd)
			{}

			Lambertian(float& p_kD, Texture* p_currentTexture) : m_usedTexture(p_currentTexture), m_cd(0)
			{}



			virtual RGBColor f(ShadeRec& sr, Point3D& wi, Point3D& w0, bool p_containsTexture = false)
			{
				if (p_containsTexture)
				{
					//get the color from the texture 
					//get the u and v 
					Triangle* currentTriangle = (Triangle*)sr.m_hitTriangle;
					ShadeRec testInterm;
					Point2D barCoor = currentTriangle->CalcBarycentric(sr.ray, testInterm);
					RGBColor textureBaseColor = currentTriangle->GetMaterial()->GetColor(barCoor.x, barCoor.y);

					return ( textureBaseColor*  m_kd * 1 / PI_NUM);
					//return (get*  m_kd * 1 / PI_NUM);
				}
				else
				{
			
					float x = 0, y = 0;
					return (m_usedTexture->GetColor(x,y) *  m_kd * 1 / PI_NUM);
				}
				
			}

			virtual RGBColor sampleF(ShadeRec& sr, Point3D& wi, Point3D& w0)
			{
				return RGBColor(0);
			}

			virtual RGBColor rho(ShadeRec& sr, Point3D& w0)
			{
				return (m_cd * m_kd );
			}

			void SetColor(RGBColor& p_color)
			{
				m_cd = p_color;
			}

			RGBColor GetColor()
			{
				return m_cd;
			}

			float GetKd()
			{
				return m_kd;
			}

			void SetKd(float kD)
			{
				m_kd = kD;
			}

		private:
			float m_kd;
			RGBColor m_cd;
			Texture* m_usedTexture;
	};
}

#endif // !__LAMBERTIAN__
